<%-- 
    Document   : schoolorder
    Created on : Dec 6, 2011, 12:37:24 AM
    Author     : fortruth
--%>
<%-- 
    Document   : user
    Created on : Sep 28, 2011, 7:12:32 AM
    Author     : Guan Junming <guan.junming@mabang.net>
--%>
<%@include file="../../WEB-INF/jspf/admin/common.jspf" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>       
        <%@include file="../../WEB-INF/jspf/admin/htmlHeader.jspf"%>
        <title>用户管理</title>
        <script type="text/javascript">
            $(function(){
                $("#orderConfirm").dialog({
                    autoOpen: false
                }); 
            });
            function showUpdate(key){
                $.getJSON("${adminModule}", {action:"select",id:key}, 
                function(data){      
                <c:forEach var="field" items="${fields}">
                        theForm.elements["${field.get('name')}"].value = data["${field.get('name')}"];
            </c:forEach>                    
                        theForm.elements["action"].value = "update";
                        $('#editor').dialog('open');
                    }
                );}
                function showConfirm(theId){
                    $('#orderConfirm').dialog('open');
                    
                    $('#orderConfirm input[name=amount]').val($("#claimAmount-"+theId).html());
                    $('#orderConfirm input[name=id]').val(theId);
                    $('#orderConfirm textarea[name=comment]').html($("#comment-"+theId).html());
                }
        </script>
    </head>
    <body>                
        <table border="1" style="width: 100%">
            <tr><td><button onclick="javascritp:showCreate();">ADD</button></td></tr>
            <c:forEach var="field" items="${fields}">
                <td>${field.get("label")}</td>  
            </c:forEach>    
            <c:forEach var="entity" items="${entities}">
                <tr>
                    <c:forEach var="field" items="${fields}">
                        <td id="${field.get("name")}-${entity.id}">${entity[field.get("name")]}</td>
                    </c:forEach>                    
                    <td><a href="javascript:showUpdate(${entity.id})">修改</a></td>
                    <td>
                        <c:choose>
                            <c:when test="${entity.valid == 1}">
                                已确认
                            </c:when>
                            <c:otherwise>
                                <a href="javascript:showConfirm('${entity["id"]}')">确认</a>
                            </c:otherwise>
                        </c:choose>
                    </td>
                    <td><a href="javascript:showDelete('${adminModule}',${entity.id})">删除</a></td>
                </tr>
            </c:forEach>
            <tr><td><button onclick="javascritp:showCreate();">ADD</button></td></tr>
        </table>
        <div id="editor">                     
            <form id="theForm" action="${adminModule}" method="POST">
                <input type="hidden" name="action" value="create"/>
                <input type="hidden" name="id"/>
                <table>
                    <c:forEach var="field" items="${fields}">
                        <c:choose>
                            <c:when test="${field.get('name') == 'id'}"></c:when>
                            <c:otherwise>
                                <tr>
                                    <td>${field.get("label")}</td><td><input name="${field.get('name')}"/></td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                    <tr style="text-align: center"><td colspan="2"><button type="submit">SUBMIT</button></td></tr>
                </table>
            </form>
        </div>
        <div id="orderConfirm" style="display: none">
            <form action="${adminModule}" method="POST">
                <input type="hidden" name="action" value="confirm"/>
                <input type="hidden" name="id" value="" />
                <table>
                    <tr><td>消费额: </td><td><input name="amount" value=""/></td></tr>
                    <tr><td>备    注: </td><td><textarea name="comment"></textarea></td></tr>
                    <tr><td colspan="2"><input type="submit"/></td></tr>
                </table>                
            </form>
        </div>
    </body>
</html>
